package com.mmall.seckill.rabbitMQ.miaosha.send;

import com.mmall.seckill.rabbitMQ.MQConfig;
import com.mmall.seckill.rabbitMQ.miaosha.MiaoshaMessage;
import com.mmall.seckill.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by megan on 2018/7/29.
 * 发送秒杀信息
 */
@Slf4j
@Service
public class SendMiaoshaMessage {

    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * 发送秒杀消息
     * @param message
     * @return
     */
    public void sendSeckill(MiaoshaMessage message){
        String msg = JsonUtil.obj2String(message);
        log.info("发送秒杀消息 --> {} ",msg);
        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE,msg);
    }
}
